import { AnyMap } from 'monk-design/utils'

export interface AdBreadcrumbNode {
  /**
   * 面包屑主键
   */
  id?: string
  /**
   * 面包屑名称
   */
  name?: string
  /**
   * 是否禁用
   */
  disabled?: boolean
  /**
   * 是否显示
   */
  hidden?: boolean
}

export class AdBreadcrumbNodeImpl implements AdBreadcrumbNode {
  id?: string
  name?: string
  disabled?: boolean
  hidden?: boolean
  /**
   * 给某个属性赋值
   * @param key
   * @param val
   * @returns
   */
  set<T extends keyof Omit<AdBreadcrumbNode, 'set' | 'copyProperty'>>(
    key: T,
    val: AdBreadcrumbNode[T]
  ) {
    this[key] = val as any
    return this
  }

  /**
   * 从对象中复制属性
   * @param map
   * @returns
   */
  copyProperty(map: AnyMap) {
    if (map instanceof Object && map !== null) {
      Object.keys(map).forEach((key) => {
        this[key] = map[key]
      })
    }
    return this
  }
}
